<template>
	<el-card shadow="never" header="个人信息">
		<el-form ref="form" :model="form" label-width="120px" style="margin-top:20px;">
			<el-form-item label="账号">
				{{form.user.loginName}}
<!--				<div class="el-form-item-msg">账号信息用于登录，系统不允许修改</div>-->
			</el-form-item>
			<el-form-item label="姓名">
				{{form.user.userName}}
			</el-form-item>
			<el-form-item label="邮箱">
				{{form.user.email}}
			</el-form-item>
			<el-form-item label="手机">
				{{form.user.mobile}}
			</el-form-item>
			<el-form-item label="所在部门">
				<ex-label v-if="form.user.orgId" code="SysOrganization" :value="form.user.orgId"></ex-label>
			</el-form-item>
			<el-form-item label="拥有角色">
				<template v-for="role in tool.current.roles()">
					<ex-label :value="role.roleName"></ex-label>
				</template>
			</el-form-item>
			<el-form-item v-if="!isProxyLogin&&replaceJobs.length>0" label="代岗信息">
				<template v-for="item in replaceJobs">
					<el-button link @click="changeUser(item)"><ex-label code="SysUser" :value="item.createUser"></ex-label></el-button>
				</template>
			</el-form-item>

<!--			<el-form-item label="性别">-->
<!--				<el-select v-model="form.sex" placeholder="请选择">-->
<!--					<el-option label="保密" value="0"></el-option>-->
<!--					<el-option label="男" value="1"></el-option>-->
<!--					<el-option label="女" value="2"></el-option>-->
<!--				</el-select>-->
<!--			</el-form-item>-->
<!--			<el-form-item label="个性签名">-->
<!--				<el-input v-model="form.about" type="textarea"></el-input>-->
<!--			</el-form-item>-->
<!--			<el-form-item>-->
<!--				<el-button type="primary">保存</el-button>-->
<!--			</el-form-item>-->
		</el-form>
	</el-card>
</template>

<script>
	import ExLabel from "@/components/exLabel/index.vue";
	import tool from "@/utils/tool";

	export default {
		computed: {
			tool() {
				return tool
			}
		},
		components: {ExLabel},
		data() {
			return {
				form: {
					user: "administrator@scuiadmin.com",
					name: "Sakuya",
					sex: "0",
					about: "正所谓富贵险中求"
				},
				replaceJobs:[],
				isProxyLogin:null,
			}
		},
		mounted() {
			this.form.user = this.$TOOL.current.user();
			this.isProxyLogin = this.$TOOL.data.get("IS_PROXY_LOGIN");
			this.replaceJobs = this.$TOOL.data.get("REPLACE_JOBS");
			if (!this.replaceJobs) {
				this.replaceJobs = [];
			}

		},
		methods:{
			async changeUser(item) {
				let confirm = await this.$confirm('请确认是否切换账号', '警告', {type: 'warning'}).then(() => {return true;}).catch(() => {return false;});
				if (!confirm) return;
				let data = {
					proxyLoginUserId: item.createUser,
					loginType:"replaceJob"
				};
				let res = await this.$API.auth.login.post(data);
				if (res.code !== 2000) {
					return;
				}
				let valid =  await this.$cache.login.assemble(res, true,this);
				if (!valid) {
					return;
				}
				window.location.href = "/";
				// //进入首页
				// this.$router.replace({
				// 	path: '/index'
				// });
			},
		}
	}
</script>

<style>
</style>
